#ifndef CABINET_H
#define CABINET_H

#include <QWidget>
#include <qpoint.h>
#include <QEvent>
#include <QTableWidget>
#include "chineseletterhelper.h"

namespace Ui {
class Cabinet;
}

class Cabinet : public QWidget
{
    Q_OBJECT

public:
    explicit Cabinet(int colNum, QString cLayout,QWidget *parent = 0);
    void setCtrlSeq(unsigned int row, char ctrlWd);
    void setCtrlSeq(QByteArray ctrlWd);
    void setCtrlIo(unsigned int row, char ctrlWd);
    void setCtrlIo(QByteArray ctrlWd);
    void setText(QStringList texts);
    void setText(int row, QString text);
    QByteArray getCtrlSeq();
    char getCtrlSeq(int row);
    QByteArray getCtrlIo();
    char getCtrlIo(int row);
    QStringList getCaseText();
    void setScreenPos(int row);
    void clearScreen();
    void clearSelection();
    void initLayout(QString cabLayout);
    int rowCount();
    QByteArray getOpenData(int row);
    void setEditState(bool enabled);//设置可编辑状态
    int findGoodsByPinyin(QString py);//拼音搜索
    void searchClear();
    ~Cabinet();

private:
    Ui::Cabinet *ui;
    bool textLock;
    bool editEnable;
    int seqNum;
    int screenIndex;
    QStringList firstLetters;
    QByteArray ctrlSeq;
    QByteArray ctrlIo;
    QString colLayout;
    QStringList caseTexts;
    void cabSplit(QString scale, QTableWidget *table);
    int getBaseCount(QString scale);
    bool eventFilter(QObject *watched, QEvent *event);
    void updateFirstLetters(QStringList l);
    void setSearchState(int row, bool searched);

    QString transLine(QString text);
signals:
    void caseClicked(QPoint);
    void caseTextsChanged(int seq, QStringList texts);

protected:
    void resizeEvent(QResizeEvent*);
private slots:
    void on_tab_cellClicked(int row, int column);
    void tab_itemChanged(QTableWidgetItem *item);
};

#endif // CABINET_H
